package source;

import beans.SenSorReading;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

public class SourceCollection01 {
    public static void main(String[] args) throws Exception {
        //创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //设置全局的并行度为1，这样子输入和输出的数据结果顺序就会一致
        env.setParallelism(1);
        //从集合中读取数据
        DataStream<SenSorReading> sensorDataStream = env.fromCollection( Arrays.asList(
                new SenSorReading("sensor_1", 1547718199L, 35.8),
                new SenSorReading("sensor_6", 1547718201L, 15.4),
                new SenSorReading("sensor_7", 1547718202L, 6.7),
                new SenSorReading("sensor_10", 1547718205L, 38.1)
                )
        );
        //直接将元素当作集合
        DataStreamSource<Integer> integerDataStreamSource = env.fromElements(1, 2, 3, 4, 5);

        //输出
        sensorDataStream.print("data");
        integerDataStreamSource.print("int");
        env.execute("dataFromCollection");
    }
}
